<script setup lang="ts">
import CinemaView from '@/components/Home/CinemaView.vue';
import ClassicMovies from '@/components/Home/ClassicMovies.vue';
import ExpectedMovies from '@/components/Home/ExpectedMovies.vue';
import HomeHot from '@/components/Home/HomeHot.vue';

import { useCounterStore } from '@/stores/counter';
import { storeToRefs } from 'pinia';

// 在pinia 获取城市
const counterStore = useCounterStore();
const { cityName } = storeToRefs(counterStore);

import { ref } from 'vue';

// tab
const active = ref(0)

</script>

<template>
  <div class="home">
    <van-sticky>
      <header>
        <div class="title">猫眼电影</div>
        <div class="tabbar">
          <div class="address" @click="$router.push('/city')">{{ cityName? cityName:'北京' }} </div>
          <van-tabs v-model:active="active" animated class="vantabs">
            <van-tab v-for="tab in ['热映', '影院', '待映', '经典电影']" :title="tab">
            </van-tab>
          </van-tabs>
          <div class="searchIcon" @click="$router.push('/search')"><van-icon name="search" color="#e54847" size="20" />
          </div>
        </div>
      </header>
    </van-sticky>

    <!-- 热映列表 -->
    <HomeHot v-if="active === 0" />
    <!-- 影院 -->
    <CinemaView v-if="active === 1"/>
    <!-- 待映列表 -->
    <ExpectedMovies v-if="active === 2" />
    <!-- 经典电影 -->
    <ClassicMovies v-if="active === 3" />
  </div>
</template>
<style lang="less" scoped>
.home {
  background-color: #f5f5f5;
  margin-bottom: 50rem;

  header {
    background-color: #fff;
    border-bottom: 1px solid #00000018;

    .title {
      background-color: #e54847;
      font-size: 18rem;
      text-align: center;
      height: rem;
      padding: .12rem;
      color: #fff;
      height: 50rem;
      display: flex;
      align-items: center;
      justify-content: space-around;
    }

    .tabbar {
      display: flex;
      width: 100vw;
      height: 44rem;
      align-items: center;
      justify-content: space-around;

      .address {
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        padding-left: 8rem;
        font-size: 15rem;
        color: #666;
      }

      .vantabs {
        width: 70vw;
      }

      .searchIcon {
        padding: 8rem;
      }
    }
  }

}

// 单行文本溢出
.text-ellipsis {
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
}

// vant组件样式
.van-tabs__line {
  background: #e54847;
}
</style>